<?php

class ProtectedController extends Controller{
	var $params = array(
		'login_url' => CMF_LOGIN_URL,
		'role'		=> 'admin'
	);
	
	function ProtectedController($p = null){
		parent::Controller();
		$this->load->helper('url');
		if( is_array($p)){
			$this->params = array_merge($this->params, $p);
		}
		$this->load->library('Login_lib');
		if( !$this->isLoggedIn() ){
			if( $this->params['login_url'] ){
				redirect($this->params['login_url']);
			}else{
				show_error('Sorry, a login page has not been provided!');
			}
		}
	}
	
	function isLoggedIn(){
		return $this->login_lib->isLoggedIn($this->params['role']);
	}
}
?>